<?php
/**
 * 自动任务获取最后的揽收日期及签收日期
    1、获取所有已发货数据
    2、
 * @author liuhua@leemanpaper.com
 * @version $20181004
 */
$domain = $argv[1];

if (empty($domain)) {
    die('No Params');
}
set_time_limit(0);
require_once(dirname(__FILE__) . '/../../lib/init.php');
cachemgr::init(false);
$_SERVER['HTTP_HOST'] = $domain;

try{
    //指定归档日期
    $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
    $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;

    $db = kernel::database();
    $sql="SELECT f.customerchnname,items.bn,sum(items.number) number 
        from  sdb_wms_deliverycomp a 
        inner join sdb_wms_deliverycomp_line b on a.id = b.deliverycomp_id
        inner join sdb_wms_deliverynote_line d on b.deliverynote_id = d.deliverynote_id
        inner join sdb_wms_delivery e on d.delivery_bn = e.delivery_bn
        inner join sdb_wms_delivery_items items on e.delivery_id=items.delivery_id
        inner join sdb_ome_shop f on e.shop_id=f.shop_id
        where a.deliverycomp_time between $beginYesterday and $endYesterday and a.status='unconfirmed'
        group by f.customerchnname,items.bn";
    $data_total = $db->select($sql);
    $postdata = array(
        'data' => $data_total,
        'busdate'=>date('Y-m-d',$beginYesterday) 
    );
    date_default_timezone_set("PRC");
    ini_set('soap.wsdl_cache_enabled', "0"); //关闭wsdl缓存
    ini_set('default_socket_timeout', 500);    // timeout
    $res=kernel::single('erpapi_rpc_qimen')->call('OmsSendWeiXin',json_encode($postdata));
    error_log(date('Y-m-d H:i:s') . '发送数据/' . var_export($res, true), 3, PUBLIC_DIR . '/autoOmsToAX' . date('Y-m-d') . '.log');  
  
}catch (Exception $e) 
{
    error_log(date('Y-m-d H:i:s') . '发送数据/' . var_export($e->getMessage(), true), 3, PUBLIC_DIR . '/autoOmsToAX' . date('Y-m-d') . '.log');
}


